﻿using Newtonsoft.Json.Linq;
using Reactive.Bindings;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WPF_ReactiveProperty_PathSearchUtil.Models;

namespace WPF_ReactiveProperty_PathSearchUtil.Util
{
    public class ListConvertFromDB
    {
        /// <summary>
        /// 将从服务器端获得的JArray数组转换为 fileList
        /// </summary>
        /// <param name="strs"></param>
        /// <param name="fileList"></param>
        public static void JArrayToList(ReactiveCollection<FileInfoModel> fileListRead, JArray fileList)
        {
            foreach (JObject fileInfo in fileList)
            {
                FileInfoModel fileInfoModel = new FileInfoModel();
                fileInfoModel.FileName.Value = fileInfo["fileName"].ToString();
                fileInfoModel.FilePath.Value = fileInfo["filePath"].ToString();
                fileInfoModel.FileType.Value = fileInfo["fileType"].ToString();
                fileInfoModel.FileSize.Value = double.Parse(fileInfo["fileSize"].ToString());
                //Console.WriteLine(fileInfo["fileDate"].ToString());
                DateTime dt = DateTime.Parse(fileInfo["fileDate"].ToString());
                Console.WriteLine(dt);
                fileInfoModel.FileDate.Value = DateTime.Parse(fileInfo["fileDate"].ToString());
                fileListRead.Add(fileInfoModel);
            }
        }

        /// <summary>
        /// 把本地db获取的list赋给filelist
        /// </summary>
        /// <param name="fileList"></param>
        /// <param name="localList"></param>
        public static void LocalToList(ReactiveCollection<FileInfoModel> fileList, Object localList)
        {
            ReactiveCollection<FileInfoModel> list = (ReactiveCollection<FileInfoModel>)localList;
            foreach (FileInfoModel fileInfo in list)
            {
                fileList.Add(fileInfo);
            }
        }
    }
}
